<template>
	<el-dialog v-model="show" title="人员管理" :width="550" :before-close="close1">
		<el-table :data="organizationDetailList" >
			<el-table-column type="index" width="50" />
			<el-table-column prop="userName" label="人员名称"></el-table-column>
			<el-table-column label="类型">
				<template #default="scope">
					<el-tag type="success" v-if="scope.row.type == 1">管理员</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="180">
				<template #default="scope">
					<div v-if="!classManage">
						<el-button type="primary" v-if="scope.row.type == 0" plain size="small"
							@click="setManage(scope.row.id,1)">设置管理员</el-button>
						<el-button type="primary" v-else plain size="small" @click="setManage(scope.row.id,0)">取消管理员</el-button>
						<el-button type="danger" plain size="small" @click="updateStatusById(scope.row.id)">删除</el-button>
					</div>
					<div v-else>
						<el-button type="primary" plain size="small" @click="addManage(scope.row.userUnionid)">指派为班级管理员</el-button>
					</div>
				</template>
			</el-table-column>
		</el-table>
	</el-dialog>

</template>

<script>
	import myMixin from '@/utils/myMixin.js'
	var that;
	export default {
		mixins: [myMixin], //混入
		props: {
			organizationId: String,
			classManage: String
		},
		data() {
			return {
				show: true,
				organizationDetailList: [],
			}
		},
		mounted() {
			that = this;
			// that.organizationId = option.organizationId;
			// that.classManage = option.classManage;

			that.getData();
		},
		methods: {
			close1() {
				this.$parent.peopleShow = false;
			},
			async updateStatusById(id) {
				//获取班级信息
				const res = await that.$asyncHttpConfig({
					url: "/organization/updateStatusById",
					data: {
						id: id
					}
				})

				that.getData();
			},
			async addManage(userUnionid) {
				const res = await that.$asyncHttpConfig({
					url: "/classname/addManage",
					data: {
						code: userUnionid,
						managerId: that.classManage
					}
				})
			},
			//设置管理员
			async setManage(id, type) {
				const res = await that.$asyncHttpConfig({
					url: "/organization/updateTypeById",
					data: {
						id: id,
						types: type
					}
				})

				that.getData();
			},
			async getData() {

				const data = await that.$asyncHttpConfig({
					url: '/organization/selectAllOrganizationDetail',
					data: {
						id: that.organizationId
					}
				})
				that.organizationDetailList = data.organizationDetailList;
				if (that.organizationDetailList.length == 0) {
					that.$hintMessage('该机构暂无人员');
				}
			},
		}
	}
</script>

<style>
	.page-background {
		position: relative;
		height: 100vh;
		overflow-y: auto;
	}

	.content1 {
		height: 94vh;
		margin: 10px;
		border-radius: 10px;
		background: #FFFFFF;
		color: #606266;
	}
</style>